home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / zoo / zoofilt.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  88 lines

  1. /* derived from: zoofilt.c 1.8 88/01/30 23:47:05 */
  2.  
  3. #ifndef LINT
  4. static char sccsid[]="@(#) $Id: zoofilt.c,v 1.5 91/07/09 01:54:15 dhesi Exp $";
  5. #endif
  6.  
  7. /*
  8. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  9. (C) Copyright 1991 Rahul Dhesi -- All rights reserved
  10.  
  11. Filter mode -- compress or decompress standard input and write
  12. to standard output.
  13. */
  14.  
  15. #include "options.h"
  16.  
  17. #ifdef FILTER
  18.  
  19. #include "zooio.h"
  20. #include "errors.i"
  21. #include "zoofns.h"
  22.  
  23. /* action */
  24. #define COMPRESS        0
  25. #define UNCOMPRESS    1
  26.  
  27. #define FTAG    ((unsigned int) 0x5a32) /* magic number */
  28.  
  29. extern unsigned int crccode;
  30.  
  31. int rdint PARMS((unsigned int *));  /* read an unsigned int */
  32. int wrint PARMS((unsigned int)); /* write an unsigned int */
  33.  
  34. /* global variable used to pass two bytes (CRC value) back from lzd to here */
  35. unsigned int filt_lzd_word;
  36.  
  37. void zoofilt (option)
  38. char *option;
  39. {
  40.     int choice;                                         /* what to do -- [de]compress */
  41.     unsigned int filetag;                            /* tag stored in input */
  42.     int stat1, stat2, stat3;                        /* status codes */
  43.     int use_lzh = 1;                                    /* use lzh instead OIS*/
  44.     extern lzc(), lzh_encode();               /* possible encoders */
  45.     extern lzd(), lzh_decode();               /* and decoders */
  46.  
  47.     while (*++option) {
  48.         switch (*option) {
  49.             case 'c':   choice = COMPRESS;    break;
  50.             case 'u':   choice = UNCOMPRESS;  break;
  51.             case 'H':   use_lzh = 0; break;    /*OIS*/
  52.             case 'h':   use_lzh = 1; break;    /*OIS*/
  53.             default:
  54.                 prterror ('f', inv_option, *option);   /* fatal error -- abort */
  55.         }
  56.     }
  57.  
  58.     crccode = 0;    /* needed whether compressing or uncompressing */
  59.  
  60.     switch (choice) {
  61.         case COMPRESS:
  62.             stat1 = wrint (FTAG);
  63.             stat2 = (use_lzh ? lzh_encode : lzc) (STDIN, STDOUT);
  64.             stat3 = wrint (crccode);
  65.             if (stat1 == 0 && stat2 == 0 && stat3 == 0)
  66.                 zooexit (0);
  67.             else {
  68.                 fprintf (stderr, "Zoo: FATAL: Compression error.\n");
  69.                 zooexit (1);
  70.             }
  71.             break;
  72.         case UNCOMPRESS:
  73.             stat1 = rdint (&filetag);
  74.             if (stat1 != 0 || filetag != FTAG)
  75.                 zooexit (1);
  76.             stat2 = (use_lzh ? lzh_decode : lzd) (STDIN, STDOUT);
  77.             if (stat2 == 0 && filt_lzd_word == crccode)
  78.                 zooexit (0);
  79.             else {
  80.                 fprintf (stderr, "Zoo: FATAL: Uncompression error.\n");
  81.                 zooexit (1);
  82.             }
  83.             break;
  84.     }
  85. } /* zoofilt */
  86.  
  87. #endif /* FILTER */
  88.